#include <project.h>
/*-------------------------------------------------------------------------


***************** Modification History ***********************************
   @doc
   @module PP1000.c - PP1000 functions |
   @end
   
$Log: /SoftPay/SPK2SIM/Source/PINPad/pp1000.c $ 
 * 
 * 8     3/20/00 12:20p Jim_b4
 * Added PINPAD_DEFINED Checks
 * 
 * 7     3/19/00 8:06p Jim_b4
 * 
 * 6     3/16/00 6:34p Jim_b4
 * Code security functionality added
 * 
 * 5     2/21/00 3:00p Jim_b4
 * Include file restructuring
 * 
 * 4     2/21/00 11:29a Jim_b4
 * Include directory restructuring
 * 
 * 3     12/22/99 12:09p Dom_b1
 * 
 * 2     10/27/99 12:08p Dom_b1
 * 
 * 1     7/19/99 5:42p Jim_b4
 * 
 * 1     7/19/99 4:26p Jim_b4
 * 
 * 6     7/13/99 5:49p Nick_t1
 * 
 * 5     6/24/99 4:14p Nick_t1
 * 
 * 4     6/23/99 11:56a Nick_t1
 * 
 * 3     6/10/99 1:42p Nick_t1
 * 
 * 2     6/09/99 11:20a Monique_b1
 * Change headers and file names for SP 2000
**************************************************************************

   Copyright (C) 1999 by VeriFone, Inc.

   All rights reserved.  No part of this software may be reproduced,
   transmitted, transcribed, stored in a retrieval system, or translated
   into any language or computer language, in any form or by any means,
   electronic, mechanical, magnetic, optical, chemical, manual or otherwise,
   without the prior written permission of VeriFone, Inc.

---------------------------------------------------------------------------*/
#define VSPP1000_C

#ifdef PINPAD_DEFINED

#include <aclconio.h>
#include <errno.h>
#include <txoinc.h>
#include <stdio.h>
#include <ascii.h>
#include <stdio.h>
#include <stdlib.h>
#include <acldev.h>
#include <string.h>
#include <aclstr.h>
#include <portdef.h>
#include <aclascii.h>
#include <applidl.h>
#include <message.h>


/*#define DEBUG_VSPP1000*/
#ifdef DEBUG_VSPP1000
#define DEBUG_95
#endif

#include <define.h>
#include <transact.h>
#include <pp1000.h>
#include <ui.h>
#include <tct.h>
#include <pinpad.h>
#include <print.h>
#include <spdebug.h>
#include <util.h>
#include <codesec.h>


/*-------------------------------------------------------------------------
    Function :    inSetKeyManagement
    Description : This function is called to set the key management mode
                  of the PIN Pad 1000. The default mode is Master Session.
                  If DUKPT is necessary, this function is called in
                  inInitPINPad().
    Parameters :
    Returns :
    Globals :
    Notes :
    Modification History :
      #     Date       Who                     Description
    ----- --------  ---------- ---------------------------------------------
      1   06/06/96  Pat_G1     Initial write.
      2   07/31/96  Page_K1    Check VS_TIMEOUT
      3   08/05/96  Donncha_H1 For the internal PINPad of the 470 must send
                               "15VISA" for MAS+DUKPT
      4   11/22/96  Donncha_H1 Moved this function from VSPP101.c
      5   12/06/96  Donncha_H1 Removed the #defines of DUKPT and implemented flags
      6   02/16/98  Betty_B1   Added code to distinguish between O460 & O470
                               This change had been made in 1.2 but somehow
                               got lost
--------------------------------------------------------------------------*/
int inSetKeyManagement() {
    char szPINBuf[PINPAD_BUFFER_SIZE];
    int inRetCode;

    pdebug(("--inSetKeyManagement--"));

    memset(szPINBuf, 0x00, sizeof(szPINBuf));
    szPINBuf[0] = SI;

    if (inGetEncryptMethod() == DUKPT)
        strcat(szPINBuf, "15DKEY");
    else
        strcat(szPINBuf, "15MKEY");

    szPINBuf[strlen(szPINBuf)] = SO;

    if (inSendPinPadData(szPINBuf, inGetPPTimeOut(), VS_TRUE) != VS_SUCCESS)
        return(PP_ERROR);               /* End if SendPinPadData fails */

    inRetCode = inRecvPinPadData(szPINBuf, inGetPPTimeOut(), sizeof(szPINBuf), VS_TRUE);

    if (inRetCode == VS_ESCAPE)         /* Aborting from terminal, via Clear key */
        return(PP_CANCEL);

    if ((inRetCode == 0) || (inRetCode == VS_TIMEOUT))
        return(PP_TIMEOUT);             /* Nothing Received */

    return(PP_CORRECT);
}

int PP1000_CODE_CHECK(char* a,char* b,short* c,char* d,unsigned char* e) {
    GET_VER(a, b, c, d, e);
    return 1;
}
#endif

#undef VSPP1000_C

